home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / BOI200P.ZIP / HILO.PAS < prev    next >
Pascal/Delphi Source File  |  1992-12-14  |  10KB  |  303 lines

  1. { $D-}
  2. {$V-}
  3.  
  4. program HiLo;
  5. { Copyright (C) 1990 Andrew J. Mead                                            }
  6. { All Rights Reserved.                                                         }
  7. { Contact POB 1155 Chapel Hill, NC 27514-1155                                  }
  8.  
  9. { Version 0.1  beta dated 12/12/90 using BBS Onliner Interface 1.20            }
  10. { Version 1.00 12/12/90 BOI 1.20 (about 23 minutes later )                     }
  11. { Vers 2.00 12/12/92 BOI 2.00                                                  }
  12.  
  13. Uses
  14.   dos,
  15.   crt,
  16.   key,
  17.   boidecl,
  18.   doorlib,
  19.   getcmbbs,
  20.   iolib,
  21.   support;
  22.  
  23. Const
  24.   bell      = #$07;
  25.   hilo_ins  = 'HILO.INS';
  26.   hilo_max  = 4096;
  27.  
  28. Var
  29.   hilo_num  : word;    { computer's number        }
  30.   guesses   : array [1..60] of word;
  31.   hilo_won  : boolean; { player success indicator }
  32.   quit      : boolean; { player quit indicator    }
  33.   hilo_char : char;    { standard input variable  }
  34.  
  35. Procedure GETINSTRUCTIONS;
  36.   begin {* GetInstructions *}
  37.     if Exist(boi_gamedir + hilo_ins) then
  38.         DisplayText(boi_gamedir + hilo_ins) { display online instructions }
  39.     else NotifySysOp(hilo_ins) { tell player to tell SysOp about missing file }
  40.   end;  {* GetInstructions *}
  41.  
  42. Procedure INITIALIZE;
  43.   begin {* Initialize *}
  44.     hilo_num := Random(hilo_max) + 1; { pick value 1..hilo_max }
  45.     quit := false;
  46.     playerpoints := 0;
  47.     hilo_won := false
  48.   end;  {* Initialize *}
  49.  
  50. Procedure PLAYGAME;
  51.   var
  52.     moved : boolean;
  53.     linein : string;
  54.  
  55.   Procedure SHOWGUESS(
  56.       guess : byte;
  57.       hilit : boolean);
  58.  
  59.     begin {* PlayGame,ShowGuess *}
  60.       PortWindow(1,1,80,boi_pagelength);
  61.       GotoPortXY(((guess - 1) div 15) * 20 + 1,((guess - 1) mod 15) + 3);
  62.       PortColor(cyan,lightgray);
  63.       SendString(IntStr(guess,2) + ')',false);
  64.       if hilit then PortColor(lightcyan,white);
  65.       SendString(IntStr(guesses[guess],5),false);
  66.       if guesses[guess] > hilo_num then
  67.         begin
  68.           if hilit then PortColor(lightgreen,white)
  69.           else PortColor(green,white);
  70.           SendString(' too high',false)
  71.         end
  72.       else if guesses[guess] < hilo_num then
  73.         begin
  74.           if hilit then PortColor(lightred,lightgray)
  75.           else PortColor(red,lightgray);
  76.           SendString(' too low',false)
  77.         end
  78.       else
  79.         begin
  80.           TextPortColor(white);
  81.           SendString(' You Got It',false)
  82.         end
  83.     end;  {* PlayGame,ShowGuess *}
  84.  
  85.   Procedure SHOWSCREEN;
  86.     var
  87.       sloop : byte;
  88.  
  89.     begin {* PlayGame,ShowScreen *}
  90.       PortWindow(1,1,80,boi_pagelength);
  91.       ClrPortScr;
  92.       PortColor(lightcyan,white);
  93.       SendString('Hi-Lo Guessing Game',true);
  94.       PortColor(cyan,lightgray);
  95.       SendString(
  96. ' # Guess Result      # Guess Result      # Guess Result      # Guess Result',
  97.           false);
  98.       if playerpoints > 0 then
  99.         begin
  100.           for sloop := 1 to playerpoints - 1 do { display each guess }
  101.               ShowGuess(sloop,false);
  102.           ShowGuess(playerpoints,true) { display and highlight last move }
  103.         end;
  104.       GotoPortXY(1,18);
  105.       PortColor(yellow,white);
  106.       SendString('Hi-Lo options: ',false);
  107.       LineWrite('[I]nstructions   ',brown,lightgray,true);
  108.       LineWrite('[T]ime   ',brown,lightgray,boi_usetime);
  109.       LineWrite('[Q]uit',brown,lightgray,true)
  110.     end;  {* PlayGame,ShowScreen *}
  111.  
  112.   Procedure WRITELINE;
  113.     var
  114.       ltime : word;
  115.  
  116.     begin {* PlayGame,WriteLine *}
  117.       ClrPortScr;
  118.       TextPortColor(lightgray);
  119.       if boi_usetime then { if timed game, see if time has expired }
  120.         begin
  121.           ltime := LeftTime + 1;
  122.           if boi_timeover then { player has run out of time }
  123.             begin
  124.               SendString(
  125.                   'Your time limit has expired.  Game is being exited.',true);
  126.               boi_timexp := true;
  127.               Exit { no need to continue }
  128.             end
  129.           else if ltime <= boi_warntime then { player is running out of time }
  130.             begin
  131.               boi_statmode := sm_time; { force status line to display time }
  132.               UpdateStatLine;
  133.               if ltime < boi_warntime then { ring bell once per minute }
  134.                 begin
  135.                   boi_warntime := ltime;
  136.                   SendString(#$07,false) { ring bell }
  137.                 end;
  138.               { tell player how much time they have left }
  139.               SendString('You have less than ' +
  140.                   IntStr(ltime,0) + ' minutes left.',true)
  141.             end
  142.         end;
  143.       { tell player their current score }
  144.       PortColor(yellow,lightgray);
  145.       SendString('You have made ',false);
  146.       PortColor(cyan,white);
  147.       SendString(IntStr(playerpoints,0),false);
  148.       PortColor(cyan,lightgray);
  149.       SendString(' guesses. ',true);
  150.       SendString('Enter your guess: ',false)
  151.     end;  {* PlayGame,WriteLine *}
  152.  
  153.   Procedure GETINPUT;
  154.     const
  155.       legalmoves = ['1'..'9','Q','I','T'];
  156.  
  157.     begin {* PlayGame,GetInput *}
  158.       TextPortColor(white);
  159.       repeat
  160.         begin
  161.           if (boi_timer - boi_stime >= 182) and (boi_statmode = sm_time) then
  162.               UpdateStatLine; { update status line every 10 seconds or so }
  163.           hilo_char := ReadPortKey;
  164.           if not (UpCase(hilo_char) in legalmoves) then
  165.               SendString(bell,false)
  166.         end
  167.       until UpCase(hilo_char) in legalmoves;
  168.       TextPortColor(white);
  169.       case UpCase(hilo_char) of
  170.           'Q' :
  171.             begin
  172.               SendString('Quit',true);
  173.               SendString('Do you really want to quit? [Y/N] ',false);
  174.               repeat hilo_char := UpCase(ReadPortKey)
  175.               until hilo_char in ['Y','N'];
  176.               if hilo_char = 'Y' then
  177.                 begin
  178.                   quit := true;
  179.                   SendString('Yes',true)
  180.                 end
  181.               else SendString('No',false)
  182.             end;
  183.           'I' :
  184.             begin
  185.               GetInstructions;
  186.               ShowScreen;
  187.               PortWindow(1,20,80,boi_pagelength)
  188.             end;
  189.           'T' :
  190.             begin
  191.               PortWindow(1,20,80,boi_pagelength);
  192.               ClrPortScr;
  193.               GotoPortXY(1,1);
  194.               if boi_usetime then SendString('You have less than ' +
  195.                   IntStr(LeftTime,0) + ' minutes remaining.',false)
  196.               else SendString('This function is not operational.',false);
  197.               GotoPortXY(1,2);
  198.               SendString('Press almost any key to continue. ',false);
  199.               ClearBuffers;
  200.               hilo_char := ReadPortKey;
  201.               ClrPortScr
  202.             end;
  203.           else
  204.             begin
  205.               boi_nextchar := hilo_char;
  206.               SetPortXY;
  207.               if playerpoints > 0 then
  208.                   ShowGuess(playerpoints,false);
  209.               PortWindow(1,20,80,boi_pagelength);
  210.               ResetPortXY;
  211.               TextPortColor(white);
  212.               GetString(linein);
  213.               moved := true
  214.             end
  215.         end
  216.     end;  {* PlayGame,GetInput *}
  217.  
  218.   Procedure PROCESSGUESS;
  219.     var
  220.       guessamount : word;
  221.       dummy       : word;
  222.  
  223.     begin {* PlayGame,ProcessGuess *}
  224.       Val(linein,guessamount,dummy);
  225.       PortWindow(1,1,80,boi_pagelength);
  226.       if (dummy = 0) and (guessamount > 0) and (guessamount < hilo_max) then
  227.         begin
  228.           Inc(playerpoints);
  229.           guesses[playerpoints] := guessamount;
  230.           ShowGuess(playerpoints,true);
  231.           GotoPortXY(1,19);
  232.           ClrPortEOL;
  233.           if guessamount = hilo_num then
  234.             begin
  235.               PortColor(lightred + blink,white + blink);
  236.               SendString('Congratulations!!!',false);
  237.               PortColor(lightgreen,white);
  238.               SendString('  You''ve Done It!!!',false);
  239.               hilo_won := true
  240.             end
  241.           else
  242.             begin
  243.               TextPortColor(lightgray);
  244.               SendString('Your guess was ',false);
  245.               if guessamount < hilo_num then
  246.                 begin
  247.                   PortColor(lightred,lightgray);
  248.                   SendString('Too Low',false)
  249.                 end
  250.               else
  251.                 begin
  252.                   PortColor(lightgreen,lightgray);
  253.                   SendString('Too High',false)
  254.                 end
  255.             end
  256.         end
  257.       else SendString(#7#7#7,false)
  258.     end;  {* PlayGame,ProcessGuess *}
  259.  
  260.   begin {* PlayGame *}
  261.     ShowScreen;
  262.     repeat
  263.       begin
  264.         PortWindow(1,20,80,boi_pagelength);
  265.         moved := false;
  266.         repeat
  267.           begin
  268.             WriteLine;
  269.             if not boi_timexp then GetInput
  270.           end
  271.         until moved or quit or boi_timexp;
  272.         if not (quit or boi_timexp) then ProcessGuess
  273.       end;
  274.     until quit or hilo_won or boi_timexp;
  275.     PortWindow(1,20,80,boi_pagelength);
  276.     ClrPortScr;
  277.     TextPortColor(lightgray)
  278.   end;  {* PlayGame *}
  279.  
  280. begin {* pHiLo *}
  281.   If boi_pagelength < 23 then AbortGame(23); { pagelength must be >= 23 lines }
  282.   if boi_allowavt then QueryUser(['1'..'4']) { offer ANSI and AVATAR modes }
  283.   else QueryUser(['1','2']);                 { offer only ANSI modes }
  284.   if WriteCopy(true) then GetInstructions;
  285.   repeat
  286.     begin
  287.       Initialize; { initialize game variables }
  288.       PlayGame;   { play the game }
  289.       EndGame('Guessers',hilo_won,bois_points,bois_lowscore) { Hall of Fame }
  290.     end
  291.   until not boi_replay { player quits, game ends, or no time left }
  292. end.  {* pHiLo *}
  293.  
  294. Copyright (C) 1990,1992 Andrew J. Mead
  295. All Rights Reserved.
  296.  
  297. For further information, contact:
  298. Andrew J. Mead
  299. POB 1155
  300. Chapel Hill, NC 27514-1155
  301. 1:3641/417 FidoNet    75:7919/417 DoorNet
  302. 1@9952 WWIVnet        1@9395 VirtualNet
  303.